@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <script src="{{url('js/lib/distpicker.data.js')}}" type="text/javascript"></script>
    <script src="{{url("js/lib/distpicker.js")}}" type="text/javascript"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <div id="cur-position">
                <span class="tit">地址设置：</span>
                <a href="{{route('Admin.Home.addressSet')}}"></a>
            </div>
        </div>
        @include("admin.common.banner-header")


        <div class="gg-step">
            <form  id="advform">
                <div class="gg-list">
                    <div class="control-group">
                        <label class="control-label">请选择省市区</label>
                        <div class="controls" id="distpicker">
                            <select tabindex="1" data-placeholder="Select here.." id="province" class="span8" style="width: 20%;height: 30px;">
                            </select>
                            <select tabindex="1" data-placeholder="Select here.." id="city" class="span8" style="width: 20%;height: 30px;">
                            </select>
                            <select tabindex="1" data-placeholder="Select here.." id="district" class="span8" style="width: 20%;height: 30px;">
                            </select>
                        </div>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">镇/街道：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入镇" name="town" id="town" value="@if($address){{$address->town}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn_send" data-id="@if($address){{$address->id}}@endif">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {
            var pp ="广东省";
            var cc ="广州市";
            var aa ="天河区";

            $('#distpicker').distpicker({
                province: pp,
                city: cc,
                district: aa
            });

            $('#btn_send').click(function () {
                var province  = $('#province').val();
                var city      = $('#city').val();
                var area      = $('#district').val();
                var town      = $('#town').val();
                var id        = $(this).data("id");

                $.ajax({
                    url: "{{route('Api.Admin.sys.setAddress')}}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        province:province,
                        city:city,
                        area:area,
                        town:town,
                        id:id,
                    },
                    success: function (obj) {
                        if (obj.level == 'success') {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose: function () {
                                        window.location.href="{{route("Admin.Home.addressInfoList")}}";
                                    }
                                }
                            });
                        } else {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }
                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

        });
    </script>
@endsection
